#pragma once


class CMulticoreTask;

class CMulticoreTaskScheduler
{
public: 
	static HRESULT Create(CMulticoreTaskScheduler * * ppScheduler);
	~CMulticoreTaskScheduler();
	HRESULT PostTask(CMulticoreTask * pTask);
	HRESULT RunAllTasks();
private: 
	CMulticoreTaskScheduler();
	HRESULT Init();
	static XINT32 WorkerThread(XUINT8 * pParam);
private:
	struct IPALCriticalSection * m_pCritSection;
	struct IPALEvent * * m_pWorkAvailable;
	struct IPALEvent * * m_pWorkDone;
	XINT32 m_fShutdown;
	struct IPALWaitable * * m_pWorkThreads;
	XUINT32 m_cNumCores;
	CMulticoreTask * m_pTaskList;
	XUINT32 m_nNextThreadNumber;
	CMulticoreTaskScheduler * m_pPoolNext;

};